package mvc.com.controls
{
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	import mvc.com.events.CustomEvent;
	import mvc.com.utility.Captcha;

	public class ControlLogin extends MovieClip
	{		
		private var viewControlCaptcha:ControlCaptcha;
		private var mcLogin:MovieClip;		
		private var btnLogin:MovieClip;
		private var txtCaptcha:TextField;
		
		public function ControlLogin($controlApp:MovieClip)
		{
			super();
			this.mcLogin=$controlApp;
			setup();
			init();
		}
		/* setup */
		private function setup():void
		{
			btnLogin=mcLogin.submit_mc;
			btnLogin.buttonMode=true;
			btnLogin.mouseChildren=false;
			btnLogin.label_txt.text="Submit";
			
			txtCaptcha=mcLogin.captcha_txt;
			txtCaptcha.maxChars=5;
			txtCaptcha.restrict="0-9";
		}
		/* init function */
		private function init():void
		{
			/* view captcha */	
			viewControlCaptcha=new ControlCaptcha(mcLogin);
			viewControlCaptcha.addEventListener(CustomEvent.ON_CHANGE_CAPTCHA,onChangeCaptcha);
			/* submit button */
			btnLogin.addEventListener(MouseEvent.CLICK,onClickListener);
		}
		private function onClickListener(evt:MouseEvent):void
		{											
			trace(viewControlCaptcha.clsCaptcha.checkCaptcha(txtCaptcha.text));
		}
		private function onChangeCaptcha(evt:CustomEvent):void
		{
			trace("change captcha: "+evt.captcha);
		}
	}
	/* End Class */
}